package de.windeln.marketing.validation;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import de.windeln.marketing.campaign.costinterval.model.CostintervalClientObject;

@Component
public class FixCostsOrNumberOfVariableMustBeGiven implements Validator{

	@Override
	public boolean supports(Class<?> clazz) {
		return clazz == CostintervalClientObject.class;
	}

	@Override
	public void validate(Object target, Errors errors) {
		CostintervalClientObject cico = (CostintervalClientObject) target;
		if(cico.getFixCosts() == 0.0 & cico.getNumberOfVariable() == 0){
			errors.rejectValue("fixCosts", "Costs information need", "One Cost Information, either Fix Costs or Number of Variable,  must be given!");
			errors.rejectValue("numberOfVariable", "Costs information need", "One Cost Information, either Fix Costs or Number of Variable,  must be given!");

		}
		
	}

}
